import {Part} from "type/Part";
import {PartGroup} from "type/PartGroup";
import {PartProvider} from "../type/PartProvider";


class PartDataConvert{
    private readonly partData: Part[];
    private readonly partGroupMap: Map<number,string> = new Map<number, string>();
    private readonly partProviderMap: Map<number,string> = new Map<number, string>();

    public constructor(data: Part[]) {
        this.partData = data;
    }

    /**
     * 设置零件组数据
     */
    setPartGroupData(partGroupData: PartGroup[]) {
        partGroupData.forEach((value: PartGroup) => {
            this.partGroupMap.set(value.id,value.groupName) ;
        }) ;
    }

    /**
     * 设置零件供应商数据
     */
    setPartProviderData(partProviderData: PartProvider[]) {
        partProviderData.forEach((value: PartProvider) => {
            this.partProviderMap.set(value.id,value.providerName) ;
        });
    }

    /**
     * 执行数据转换
     */
    convert() {
        this.partData.forEach(part => {
            part.partGroup = this.partGroupMap.get(part.partGroup as number) + "";
            part.partProvider = this.partProviderMap.get(part.partProvider as number) + "";
        }) ;
    }
}

export default PartDataConvert;